package com.minelx.scriptbuilder.parse.matcher;

import com.minelx.sequence.IStringScanner;
import com.minelx.sequence.ReturnMatcher;
import com.minelx.scriptbuilder.script.IVariable;
import com.minelx.scriptbuilder.script.attribute.value.IntValue;

public class DigitMatcher implements ReturnMatcher<IVariable, IStringScanner> {

	@Override
	public boolean isMatch(IStringScanner scanner) {
		return scanner.existsIf(Character::isDigit);
	}

	@Override
	public IVariable onMatched(IStringScanner scanner) {
		return IVariable.immediate(new IntValue(Integer.parseInt(scanner.collect(Character::isDigit))));
	}
}
